package Hero;


public class Hero {int exp;
int level;

    public Hero(int exp){
        if(exp<0){
            this.exp=0;
            this.level=0;
        }
        else if(exp>getMaxExp()){
            this.exp=getMaxExp();
            this.level=getMaxLevel();
        }
        else{
            this.exp=exp;
            int level=0;
            while((exp=exp-getExp(level+1))>=0) {
                level++;
            }
            this.level=level;
        }
    }
    public Hero(){
        this(0);
    }
    int getMaxLevel(){
        return 30;
    }
    int getMaxExp(){
        return getExp(30);
    }
    int getExp(int level){
        return 30*(level*level*level+5*level)-80;
    }

    public static void main(String[] args) {
        System.out.println("========无参构造==========");
        Hero a=new Hero();
        System.out.println(a.exp);
        System.out.println(a.level);
        System.out.println("========有参构造==========");
        Hero hero2=new Hero(50000);
        System.out.println(hero2.exp);
        System.out.println(hero2.level);
    }
    }

